package net.xdclass.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.xdclass.enums.BizCodeEnum;
import net.xdclass.request.LockCouponRecordRequest;
import net.xdclass.service.CouponRecordService;
import net.xdclass.util.JsonData;
import net.xdclass.vo.CouponRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * @Author NJUPT wly
 * @Date 2021/9/16 11:48 下午
 * @Version 1.0
 */
@RequestMapping("/api/coupon_record/v1")
@RestController
public class CouponRecordController {

    @Autowired
    private CouponRecordService couponRecordService;

    @ApiOperation("分页查询我的优惠券列表")
    @GetMapping("page")
    public JsonData page(@RequestParam(value = "page",defaultValue = "1")int page,
                         @RequestParam(value = "size",defaultValue = "10")int size){

        Map<String,Object> pageInfo = couponRecordService.page(page,size);

        return JsonData.buildSuccess(pageInfo);
    }

    @ApiOperation("查询优惠券记录详情")
    @GetMapping("detail/{coupon_id}")
    public JsonData getCouponRecordDetail(@ApiParam("优惠券id") @PathVariable("coupon_id")long couponId){
        CouponRecordVO couponRecordVO = couponRecordService.findById(couponId);
        return couponRecordVO == null ? JsonData.buildResult(BizCodeEnum.COUPON_NO_EXITS):JsonData.buildSuccess(couponRecordVO);
    }

    @ApiOperation("rpc-锁定优惠券记录")
    @PostMapping("lock_records")
    public JsonData lockCouponRecords(@ApiParam("锁定优惠券请求对象") @RequestBody LockCouponRecordRequest recordRequest){

        JsonData jsonData = couponRecordService.lockCouponRecords(recordRequest);
        return jsonData;
    }




}
